home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / Extras / TicTacToe / Command.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.8 KB  |  107 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. /////////////////////////////////////////////////////////
  22. // Command.C: Manage a set of command buttons
  23. /////////////////////////////////////////////////////////
  24. #include "stdlib.h"
  25. #include "TicTacToe.h"
  26. #include "Command.h"
  27. #include "Engine.h"
  28. #include <Xm/Form.h>
  29. #include <Xm/PushB.h>
  30.  
  31. Command::Command ( Widget     parent, 
  32.           TicTacToe *game, 
  33.           char      *name ) : UIComponent ( name )
  34. {
  35.     _game = game;    
  36.     
  37.     // Set up an XmForm widget to manage the buttons
  38.     
  39.     _w = XmCreateForm ( parent, _name, NULL, 0 );
  40.     
  41.     installDestroyHandler();    
  42.     
  43.     // Create the command buttons and attach callbacks
  44.     
  45.     _newGame = 
  46.     XtVaCreateManagedWidget ( "newGame", 
  47.                  xmPushButtonWidgetClass, _w,
  48.                  XmNtopOffset,        5,
  49.                  XmNbottomOffset,     5,
  50.                  XmNleftOffset,       5,
  51.                  XmNtopAttachment,    XmATTACH_FORM,
  52.                  XmNleftAttachment,   XmATTACH_FORM,
  53.                  XmNrightAttachment,  XmATTACH_NONE,
  54.                  XmNbottomAttachment, XmATTACH_FORM,
  55.                  NULL );
  56.     
  57.     _quit = 
  58.     XtVaCreateManagedWidget ( "quit", 
  59.                  xmPushButtonWidgetClass, _w,
  60.                  XmNtopOffset,        5,
  61.                  XmNbottomOffset,     5,
  62.                  XmNrightOffset,      5,
  63.                  XmNtopAttachment,    XmATTACH_FORM,
  64.                  XmNleftAttachment,   XmATTACH_NONE,
  65.                  XmNrightAttachment,  XmATTACH_FORM,
  66.                  XmNbottomAttachment, XmATTACH_FORM,
  67.                  NULL );
  68.     
  69.     XtAddCallback ( _newGame, 
  70.            XmNactivateCallback, 
  71.            &Command::newGameCallback, 
  72.            (XtPointer) this );
  73.     
  74.     XtAddCallback ( _quit, 
  75.            XmNactivateCallback,
  76.            &Command::quitCallback, 
  77.            (XtPointer) this );
  78. }
  79.  
  80. void Command::newGameCallback ( Widget, 
  81.                    XtPointer clientData, 
  82.                    XtPointer )
  83. {
  84.     Command *obj = (Command *) clientData;
  85.     
  86.     obj->newGame();
  87. }
  88.  
  89. void Command::newGame()
  90. {
  91.     _game->engine()->reset();
  92. }
  93.  
  94. void Command::quitCallback ( Widget, 
  95.                 XtPointer clientData, 
  96.                 XtPointer )
  97. {
  98.     Command *obj = (Command *) clientData;
  99.     
  100.     obj->quit();
  101. }
  102.  
  103. void Command::quit()
  104. {
  105.     _game->engine()->quit();
  106. }
  107.